from flask import request,Blueprint,json
from db import db
import time,requests
from datetime import datetime

flame_db=Blueprint("flame_db",__name__)

@flame_db.route('/flame')
def flame():
    c=0
    sql="select * from flame1 where name='花园'"
    res=db.find(sql)
    min=res['min']
    max=res['max']
    sql1="select * from flame1 where name='西瓜'"
    res1=db.find(sql1)
    min1=res1['min']
    max1=res1['max']
    while c<10:
        c+=1
        time.sleep(5)
        a=requests.get('http://localhost:5001/')
        b=json.loads(a.test)
        now=datetime.strftime(datetime.now(),'%Y-%m-%d %H:%M:%S')
        print(b)
        if int(b)<min or int(b)>max:
            sql="insert into flame2(tem,nid,create_time) values(%d,%d,'%s')"%(int(b),int(res['id']),now)
            db.update(sql)
            db.commit()
        if int(b)<min1 or int(b)>max1:
            sql="insert into flame2(tem,nid,create_time) values(%d,%d,'%s')"%(int(b),int(res['id']),now)
            db.update(sql)
            db.commit()

    return 666













